﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// RestaurantManager 的摘要说明
/// </summary>
/// 
using Global;
using BussinessLib;
public class RestaurantManager:BaseManager
{
	
    DataTable m_DataTable;
    Restaurant m_Res;
    Helper m_DataAccess;
    public RestaurantManager()
    {
        //m_DataTable = new DataTable();
        m_Res = new Restaurant();
        m_DataAccess = new Helper();
      
    }
   


    ///-----------------------------------------------------
    bool BaseManager.AddObject(object obj)//增加餐馆
    {
        Restaurant res = (Restaurant)obj;
        string strSql;

        string strName = res.GetName();
        string strAddress = res.GetAddress();
        string strTel = res.GetTel();
        int iTableNum = res.GetTableNum();
        int iConsumeMin = res.GetConsumeMin();
        int iConsumeMax = res.GetConsumeMax();
        string strCity = res.GetCity();
        string strDesc = res.GetDesc();

        strSql = "insert into  Restaurant(R_sName,R_sAddress,R_sTel,R_nTableNum,R_fMinCost,R_fMaxCost,R_sCity,R_sDesc)values('"
            + strName + "','" + strAddress + "','" + strTel + "'," +
            iTableNum + "," + iConsumeMin + "," + iConsumeMax + ",'" + strCity + "','" + strDesc + "')";

        return m_DataAccess.ExecuteSql(strSql);


    }
    bool BaseManager.DeleteObject(object obj)//删除餐馆
    {
        Restaurant res = (Restaurant)obj;
        int iID = res.GetID();
        string strSql = "delete from Restaurant where R_nID  = " + iID;
        return m_DataAccess.ExecuteSql(strSql);
    }
   bool BaseManager.UpdateObject(object obj)//更新餐馆
    {

       Restaurant res = (Restaurant)obj;
        int iID = res.GetID();
        string strName = res.GetName();
        string strAddress = res.GetAddress();
        string strTel = res.GetTel();
        int iTableNum = res.GetTableNum();
        int iConsumeMin = res.GetConsumeMin();
        int iConsumeMax = res.GetConsumeMax();
        string strCity = res.GetCity();
        string strDesc = res.GetDesc();




        string strSql = "update Restaurant set R_sName = '  " + strName + "' ,R_sAddress =  '"
            + strAddress
            + "',R_sTel =  '" + strTel + "',R_nTableNum = "
            + iTableNum + ",R_fMinCost = " + iConsumeMin
                + ", R_fMaxCost = " + iConsumeMax + " ,R_sCity = '" + strCity
            + "', R_sDesc = '" + strDesc + "' where R_nID =  " + iID;



        return m_DataAccess.ExecuteSql(strSql);
    }


    ///-----------------------------------------------------_____________________________
    public DataTable SearchRestauarant(string strResName, string strResCity)// 搜索餐馆
    {
        //这个接口提供给订单时需要再做修改
        string strSql = "";
        if (strResName == "" && strResCity == "")
        {
            strSql = "select * from Restaurant ";
        }
        else if (strResName == "" && strResCity != "")
        {
            strSql = "select * from Restaurant where R_sCity = '" + strResCity + "'";
        }
        else if (strResName != "" && strResCity == "")
        {
            strSql = "select * from Restaurant where R_sName = '" + strResName + "'";
        }
        else if (strResName != "" && strResCity != "")
        {
            strSql = "select * from Restaurant where R_sName = '" + strResName + "'and R_sCity = " + strResCity + "'";
        }


        m_DataTable = m_DataAccess.ExecuteDataTable(strSql);




        return m_DataTable;

    }
}
